var that, g, _tools = require("../../utils/tools.js"),
  _util = require("../../utils/util.js"),
  app = getApp(),
  page = app.page;

Component({
  options: {
    addGlobalClass: !0
  },
  properties: {
    isShow: {
      type: Boolean
    },
    mainColor: {
      type: String,
      value: "#1155cc"
    }
  },
  data: {
    avatar: '',
    nickname: '',
    image: app.srcRoot + "login-bg.png",
    isEdit: false,
    radio: !1,
  },
  attached: function () {
    g = this, that = getCurrentPages()[getCurrentPages().length - 1];
    if(getApp().userInfo.nickName && "游客" != getApp().userInfo.nickName){
      g.setData({
        isEdit: true,
        avatar: getApp().userInfo.avatarUrl,
        nickname: getApp().userInfo.nickName,
      })
    } else {
      g.setData({
        isEdit: false
      })
    }
  },
  observers: {
    mainColor: function (t) {
      this.setData({
        textColor: (0, _tools.isDark)(t)
      });
    }
  },

  methods: {
    onChooseAvatar(e) {
      var system = wx.getStorageSync("system");
      _tools.uploadImg([e.detail.avatarUrl], function (t) {
        g.setData({
          avatar: system.attachurl + t
        })
      })
    },
    isShow: function (t) {
      this.data.isShow && that.setData({
        isLogin: !1
      }), t.currentTarget.dataset.type && g.triggerEvent("cancel");
    },
    radio: function(t) {
      g.setData({
          radio: !g.data.radio
      });
  },
  html_page: function(t) {
      let url = t.currentTarget.dataset.type == 1 ? 'https://shequxcx.legalhhr.com/agreement_reg.html' : 'https://shequxcx.legalhhr.com/agreement_privacy.html'
      wx.navigateTo({
        url: '/page/web/index?url=' + url,
      })
  },
      getUserInfo: function (t) {
      console.log(this.data.nickname)
      if (!this.data.nickname) {
        wx.showToast({
          icon: "none",
          title: "用户名不能为空"
        })
        return false;
      }
      if (!this.data.avatar) {
        wx.showToast({
          icon: "none",
          title: "请上传头像"
        })
        return false;
      }
      if (!this.data.radio && !this.data.isEdit) {
        wx.showToast({
          icon: "none",
          title: "请阅读并同意协议"
        })
        return false;
      }
      var e = {
        avatarUrl: this.data.avatar,
        city: "",
        country: "",
        gender: 0,
        language: "",
        nickName: this.data.nickname
      };
      
      _tools.updeta(e)
      wx.getLocation({
        type: "wgs84",
        success: function(e) {
            return getApp().userAddress = e;
        },
        fail: console.log
      })
      g.setData({
        isShow:false
      })
      // (0, )(t.detail.userInfo)
      // console.log(t)
      // "getUserInfo:ok" == t.detail.errMsg ? (0, _tools.updeta)(t.detail.userInfo) : (that.setData({
      //   updeta: !1
      // }), console.log("用户取消授权"), g.triggerEvent("cancel"));
    },
    // 用户修改昵称
    getNickname(e) {
      let nickname = e.detail.value;
      this.setData({
        nickname: nickname
      })
    },
    touchmove: function () {}
  }
});